import request from "@/utils/request";
const SERVICE_MANAGER = "serviceManager";
const ServiceManagerAPI = {
  getPage(queryParams?: BuildWorkFlowPageQuery) {
    return request<any, PageResult<BuildServiceManagerVo[]>>({
      url: `${SERVICE_MANAGER}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /** 添加服务*/
  add(data: BuildServiceManagerForm) {
    return request({
      url: `${SERVICE_MANAGER}/add`,
      method: "post",
      data: data,
    });
  },
  getFormData(id: number) {
    return request<any, BuildServiceManagerForm>({
      url: `${SERVICE_MANAGER}/${id}/form`,
      method: "get",
    });
  },
  update(id: number, data: BuildServiceManagerForm) {
    return request({
      url: `${SERVICE_MANAGER}/${id}`,
      method: "put",
      data: data,
    });
  },
  deleteByIds(ids: string) {
    return request({
      url: `${SERVICE_MANAGER}/${ids}`,
      method: "delete",
    });
  },
  start(id: number) {
    return request.post(`/${SERVICE_MANAGER}/${id}/start`);
  },
  stop(id: number) {
    return request.post(`/${SERVICE_MANAGER}/${id}/stop`);
  },
  restart(id: number) {
    return request.post(`/${SERVICE_MANAGER}/${id}/restart`);
  },
  getLogs(cicdConfigId: number, serviceCode: string) {
    return request<any, string>({
      url: `${SERVICE_MANAGER}/${cicdConfigId}/${serviceCode}/logs`,
      method: "get",
    });
  },
};

export default ServiceManagerAPI;
export interface BuildWorkFlowRequest {
  serviceName?: string;
}
/** 服务构建管理分页查询参数 */
export interface BuildWorkFlowPageQuery extends PageQuery {
  serviceName?: string;
  pageNum: number;
  pageSize: number;
}
/**
 * 文件API类型声明
 */
export interface BuildServiceManagerVo {
  id: number;
  cicdConfigId: number;
  serviceName: string;
  version: string;
  description: string;
  status: string;
  type: string;
  path: string;
  port: string;
  configPath: string;
  logPath: string;
  startCommand: string;
  stopCommand: string;
  restartCommand: string;
  checkCommand: string;
  checkInterval: string;
  checkTimeout: string;
  checkFailures: string;
  createTime: Date;
  updateTime: Date;
}
export interface BuildServiceManagerForm {
  id?: number | null;
  cicdConfigId?: number | null;
  serviceName?: string;
  version?: string;
  description?: string;
  status?: string;
  type?: string;
  path?: string;
  port?: number;
  configPath?: string;
  logPath?: string;
  startCommand?: string;
  stopCommand?: string;
  restartCommand?: string;
  checkCommand?: string;
  checkInterval?: number;
  checkTimeout?: number;
  checkFailures?: number;
}
